/*
 * 上海远境文化传媒有限公司 版权所有
 */
package repository;

import ext.dbutils.DBUtils;
import models.base.Corp;
import org.sql2o.Connection;
import org.sql2o.Query;
import play.Logger;

import java.util.List;

/**
 * 部门管理用的原生查询.
 */
public class DeptRepository {

    public static List<String> getInvalidCorpDeptIds(Corp rootCorp) {
        String sql = "select d.id " +
                "from depts d left join depts dp on d.parent_id=dp.id " +
                "    left join corps pc on dp.corp_id=pc.id " +
                "where d.corp_id= :rootCorpId and dp.corp_id<>d.corp_id";

        try (Connection connection = DBUtils.sql2o().open()) {
            Logger.info("LOG34961: getInvalidCorpDeptIds sql=" + sql);
            Query query = connection.createQuery(sql)
                    .addParameter("rootCorpId", rootCorp.rootCorpId());

            List<String> lines = query.executeAndFetch(String.class);
            Logger.info("LOG06863: lines = " + lines);
            return lines;
        }
    }

}
